package com.sky.controller.admin;

import com.sky.dto.CategoryDTO;
import com.sky.dto.CategoryPageQueryDTO;
import com.sky.entity.Category;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.ClassifyService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RequestMapping("/admin/category")
@RestController
@RequiredArgsConstructor
public class ClassifyController {
    private final ClassifyService classifyService;

    /**
     * 页
     *
     * @param categoryPageQueryDTO 类别页面查询dto
     * @return {@link Result}<{@link ?}>
     */
    @GetMapping("/page")
    public Result<?> page(CategoryPageQueryDTO categoryPageQueryDTO) {
        PageResult pageResult = classifyService.page(categoryPageQueryDTO);
        return Result.success(pageResult);
    }

    /**
     * 获取类别列表
     *
     * @param categoryDTO 类别dto
     * @return {@link Result}<{@link ?}>
     */
    @GetMapping("/list")
    public Result<?> getCategoryList(CategoryDTO categoryDTO) {
        List<Category> category = classifyService.getCategoryList(categoryDTO);
        return Result.success(category);
    }

    /**
     * 添加类别
     *
     * @param categoryDTO 类别dto
     * @return {@link Result}<{@link ?}>
     */
    @PostMapping
    public Result<?> addCategory(@RequestBody CategoryDTO categoryDTO){
        classifyService.addCategory(categoryDTO);
        return Result.success();
    }

    /**
     * 状态类别
     *
     * @param id     id
     * @param status 地位
     * @return {@link Result}<{@link ?}>
     */
    @PostMapping("/status/{status}")
    public Result<?> statusCategory(String id,@PathVariable int status) {
        classifyService.statusCategory(id,status);
        return Result.success();
    }

    /**
     * 删除类别
     *
     * @param id id
     * @return {@link Result}<{@link ?}>
     */
    @DeleteMapping
    public Result<?> deleteCategory(String id){
        classifyService.deleteCategory(id);
        return Result.success();
    }

    /**
     * 使现代化
     *
     * @param categoryDTO 类别dto
     * @return {@link Result}<{@link ?}>
     */
    @PutMapping
    public Result<?> update(@RequestBody CategoryDTO categoryDTO) {
        classifyService.update(categoryDTO);
        return Result.success();
    }
}
